/**
 * @description 注册
 */
//公用样式 
require('../../assets/css/index.less');

//引入weui库
require('../../assets/lib/weui/weui.css');
let weui = require('../../assets/lib/weui/weui.js');
//引入图标
require('../../assets/fonts/iconfont.css');
//当前页面样式
require('./sport-badge.less');

//工具函数 utils
const dom = require('../../utils/dom');
const local = require('../../utils/local.js');
//引入axios封装的文件
let https = require('../../utils/https.js');

dom.isLogin()



//DOM加载事件
dom.ready(function () {
       //后退
  dom.addEvent('#goBack',function(){
    history.go(-1);

  })
 
    //模拟徽章图像
    let badgeArr = [
        require('../../assets/imgs/mybadge01.jpg'),
        require('../../assets/imgs/mybadge02.jpg'),
        require('../../assets/imgs/mybadge03.jpg'),
        require('../../assets/imgs/mybadge04.jpg'),
        require('../../assets/imgs/mybadge05.jpg'),
        require('../../assets/imgs/mybadge06.jpg'),
        require('../../assets/imgs/mybadge07.jpg'),
        require('../../assets/imgs/mybadge08.jpg'),
        require('../../assets/imgs/mybadge09.jpg')
    ]


    //获取运动徽章
    function getBadge() {
        https.get('/api/exercise/badge', function (res) {
            let { errno, data } = res;
            if (errno == 0) {
                // console.log(data);

                data.map(v => {
                    // console.log(v);
                    dom.getEle('#badge-content').innerHTML += `
                    <li>
                    <img src="${badgeArr[v.id - 1]}" alt="">
                    <span>${v.name}</span>
                  </li>
                    `
                })
                dom.getEle('#badge-content').innerHTML += `
                <li>
                <img src="${badgeArr[badgeArr.length - 1]}" alt="">
              </li>
                `
            }
        })
    }

    getBadge()

    // 获取今日排名
    function rank(){
        https.get('/api/user/info',function(res){
            let {errno,data}=res;
            console.log(data);
            if(errno==0){
                dom.getEle('#ranking').innerHTML=data.ranking;
            }
        })
    }

    rank()

})
